<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::TestFixtures</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveRecord::TestFixtures 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/activerecord/lib/active_record/fixtures_rb.html">activerecord/lib/active_record/fixtures.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  
    <!-- Namespace -->
    <div class="sectiontitle">Namespace</div>
    <ul>
      
        <li>
          <span class="type">MODULE</span>
          <a href="TestFixtures/ClassMethods.html">ActiveRecord::TestFixtures::ClassMethods</a>
        </li>
      
    </ul>
  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TestFixtures.html#method-i-after_teardown">after_teardown</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>B</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TestFixtures.html#method-i-before_setup">before_setup</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TestFixtures.html#method-i-enlist_fixture_connections">enlist_fixture_connections</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TestFixtures.html#method-i-run_in_transaction-3F">run_in_transaction?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TestFixtures.html#method-i-setup_fixtures">setup_fixtures</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TestFixtures.html#method-i-teardown_fixtures">teardown_fixtures</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-after_teardown">
            
              <b>after_teardown</b>()
            
            <a href="TestFixtures.html#method-i-after_teardown" name="method-i-after_teardown" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-after_teardown_source')" id="l_method-i-after_teardown_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/02acd95d5700ea868c34f5d260882fda3cc836d3/activerecord/lib/active_record/fixtures.rb#L716" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-after_teardown_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/fixtures.rb, line 716</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">after_teardown</span>
  <span class="ruby-keyword">super</span>
  <span class="ruby-identifier">teardown_fixtures</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-before_setup">
            
              <b>before_setup</b>()
            
            <a href="TestFixtures.html#method-i-before_setup" name="method-i-before_setup" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-before_setup_source')" id="l_method-i-before_setup_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/02acd95d5700ea868c34f5d260882fda3cc836d3/activerecord/lib/active_record/fixtures.rb#L711" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-before_setup_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/fixtures.rb, line 711</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">before_setup</span>
  <span class="ruby-identifier">setup_fixtures</span>
  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-enlist_fixture_connections">
            
              <b>enlist_fixture_connections</b>()
            
            <a href="TestFixtures.html#method-i-enlist_fixture_connections" name="method-i-enlist_fixture_connections" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-enlist_fixture_connections_source')" id="l_method-i-enlist_fixture_connections_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/02acd95d5700ea868c34f5d260882fda3cc836d3/activerecord/lib/active_record/fixtures.rb#L893" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-enlist_fixture_connections_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/fixtures.rb, line 893</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">enlist_fixture_connections</span>
  <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">connection_handler</span>.<span class="ruby-identifier">connection_pool_list</span>.<span class="ruby-identifier">map</span>(&amp;<span class="ruby-value">:connection</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-run_in_transaction-3F">
            
              <b>run_in_transaction?</b>()
            
            <a href="TestFixtures.html#method-i-run_in_transaction-3F" name="method-i-run_in_transaction-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-run_in_transaction-3F_source')" id="l_method-i-run_in_transaction-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/02acd95d5700ea868c34f5d260882fda3cc836d3/activerecord/lib/active_record/fixtures.rb#L838" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-run_in_transaction-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/fixtures.rb, line 838</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">run_in_transaction?</span>
  <span class="ruby-identifier">use_transactional_fixtures</span> <span class="ruby-operator">&amp;&amp;</span>
    <span class="ruby-operator">!</span><span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">uses_transaction?</span>(<span class="ruby-identifier">method_name</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-setup_fixtures">
            
              <b>setup_fixtures</b>()
            
            <a href="TestFixtures.html#method-i-setup_fixtures" name="method-i-setup_fixtures" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-setup_fixtures_source')" id="l_method-i-setup_fixtures_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/02acd95d5700ea868c34f5d260882fda3cc836d3/activerecord/lib/active_record/fixtures.rb#L843" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-setup_fixtures_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/fixtures.rb, line 843</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">setup_fixtures</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">configurations</span>.<span class="ruby-identifier">blank?</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">pre_loaded_fixtures</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">use_transactional_fixtures</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-string">'pre_loaded_fixtures requires use_transactional_fixtures'</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@fixture_cache</span> = {}
  <span class="ruby-ivar">@fixture_connections</span> = []
  <span class="ruby-identifier">@@already_loaded_fixtures</span> <span class="ruby-operator">||=</span> {}

  <span class="ruby-comment"># Load fixtures once and begin transaction.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">run_in_transaction?</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">@@already_loaded_fixtures</span>[<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>]
      <span class="ruby-ivar">@loaded_fixtures</span> = <span class="ruby-identifier">@@already_loaded_fixtures</span>[<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>]
    <span class="ruby-keyword">else</span>
      <span class="ruby-ivar">@loaded_fixtures</span> = <span class="ruby-identifier">load_fixtures</span>
      <span class="ruby-identifier">@@already_loaded_fixtures</span>[<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>] = <span class="ruby-ivar">@loaded_fixtures</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@fixture_connections</span> = <span class="ruby-identifier">enlist_fixture_connections</span>
    <span class="ruby-ivar">@fixture_connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">connection</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">begin_transaction</span> <span class="ruby-identifier">joinable</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-comment"># Load fixtures for every test.</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">FixtureSet</span>.<span class="ruby-identifier">reset_cache</span>
    <span class="ruby-identifier">@@already_loaded_fixtures</span>[<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>] = <span class="ruby-keyword">nil</span>
    <span class="ruby-ivar">@loaded_fixtures</span> = <span class="ruby-identifier">load_fixtures</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Instantiate fixtures for every test if requested.</span>
  <span class="ruby-identifier">instantiate_fixtures</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">use_instantiated_fixtures</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-teardown_fixtures">
            
              <b>teardown_fixtures</b>()
            
            <a href="TestFixtures.html#method-i-teardown_fixtures" name="method-i-teardown_fixtures" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-teardown_fixtures_source')" id="l_method-i-teardown_fixtures_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/02acd95d5700ea868c34f5d260882fda3cc836d3/activerecord/lib/active_record/fixtures.rb#L877" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-teardown_fixtures_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/fixtures.rb, line 877</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">teardown_fixtures</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">configurations</span>.<span class="ruby-identifier">blank?</span>

  <span class="ruby-comment"># Rollback changes if a transaction is active.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">run_in_transaction?</span>
    <span class="ruby-ivar">@fixture_connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">connection</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">rollback_transaction</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">transaction_open?</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@fixture_connections</span>.<span class="ruby-identifier">clear</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">FixtureSet</span>.<span class="ruby-identifier">reset_cache</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">clear_active_connections!</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    